package com.work.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.work.entity.ent.UserEnterpriseAssociation;
import com.work.mapper.EnterpriseAssociationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Slf4j
@Service
public class EnterpriseAssociationService extends ServiceImpl<EnterpriseAssociationMapper, UserEnterpriseAssociation> {

    //    根据企业id查询用户id列表
    public List<Long> getUserByEnterpriseId(Long enterpriseId) {
        return Optional.ofNullable(
                        super.list(
                                Wrappers.lambdaQuery(UserEnterpriseAssociation.class)
                                        .eq(UserEnterpriseAssociation::getUserId, enterpriseId)
                        )
                ).map(userEnterpriseAssociations -> userEnterpriseAssociations.stream()
                        .map(UserEnterpriseAssociation::getUserId)
                        .toList())
                .orElseGet(Collections::emptyList);
    }

}
